<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>新增借阅 - 图书管理系统</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css">
</head>
<body>
<nav th:replace="fragments/navbar :: navbar"></nav>

<div class="container mt-4">
    <div class="row mb-4">
        <div class="col-md-6">
            <h2>新增借阅记录</h2>
        </div>
        <div class="col-md-6 text-right">
            <a href="/borrows" class="btn btn-secondary">返回列表</a>
        </div>
    </div>

    <div class="row">
        <div class="col-md-8 offset-md-2">
            <div class="card">
                <div class="card-header">
                    <h3>办理借书</h3>
                </div>
                <div class="card-body">
                    <!-- 错误提示 -->
                    <div th:if="${error}" class="alert alert-danger mb-4">
                        <span th:text="${error}"></span>
                    </div>

                    <form th:action="@{/borrows/borrow}" method="post">
                        <div class="form-group">
                            <label for="bookId">选择图书（有库存） <span class="text-danger">*</span></label>
                            <select class="form-control" id="bookId" name="bookId" required>
                                <option value="">-- 请选择图书 --</option>
                                <option th:each="book : ${books}"
                                        th:value="${book.id}"
                                        th:text="${book.title + '（作者：' + book.author + '，库存：' + book.stock + '）'}">
                                </option>
                            </select>
                        </div>
                        <div class="form-group">
                            <label for="readerId">选择读者 <span class="text-danger">*</span></label>
                            <select class="form-control" id="readerId" name="readerId" required>
                                <option value="">-- 请选择读者 --</option>
                                <option th:each="reader : ${readers}"
                                        th:value="${reader.id}"
                                        th:text="${reader.name + '（电话：' + (reader.phone ?: '无') + '）'}">
                                </option>
                            </select>
                        </div>
                        <div class="text-right">
                            <a href="/borrows" class="btn btn-secondary mr-2">取消</a>
                            <button type="submit" class="btn btn-primary">确认借书</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>